Appearance
入门指南
这一节为如何开始使用Spring AI提供了起点。
你应该按照以下步骤,在每个后续章节中,根据您的需求遵循。
| Spring AI 支持 Spring Boot 3.4.x 和 3.5.x。 |
|---|
Spring Boot 初始化器
前往 start.spring.io 并选择您希望在新应用中使用的 AI 模型和向量存储。
Artifact Repositories
发布 - 使用 Maven 中心
Spring AI 1.0.0 以后版本可以通过 Maven Central 获取。 无需额外的仓库配置。请确保在构建文件中已启用 Maven Central 仓库。
xml
<!-- Maven Central is included by default in Maven builds.
You usually don’t need to configure it explicitly,
but it's shown here for clarity. -->
<repositories>
<repository>
<id>central</id>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
</repositories>Snapshot - Add Snapshot Repositories
要使用最新的开发版本(例如 1.1.0-SNAPSHOT )或更早的里程碑版本(在1.0.0之前),您需要在构建文件中添加以下截取仓库。
请在你的Maven或Gradle构建文件中,添加以下仓库定义:
xml
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<releases>
<enabled>false</enabled>
</releases>
</repository>
<repository>
<name>Central Portal Snapshots</name>
<id>central-portal-snapshots</id>
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>注意: 当使用Maven配合Spring AI快照时,请确保您的Maven镜像配置正确。如果你在 settings.xml 号Maven镜像配置中设置了类似以下内容:
xml
<mirror>
<id>my-mirror</id>
<mirrorOf>*</mirrorOf>
<url>https://my-company-repository.com/maven</url>
</mirror>野字符 * 会将所有仓库请求重定向到您的镜像,从而阻止对Spring快照仓库的访问。要修复此问题,请将 mirrorOf 的配置修改为排除Spring仓库:
xml
<mirror>
<id>my-mirror</id>
<mirrorOf>*,!spring-snapshots,!central-portal-snapshots</mirrorOf>
<url>https://my-company-repository.com/maven</url>
</mirror>这个配置使得Maven可以直接访问Spring快照仓库,同时仍然使用本地镜像来解决其他依赖项。
依赖管理
Spring AI的物料清单(BOM)指定了在特定版本中使用的所有Spring AI依赖项的推荐版本。 这是一个基于BOM的版本,它仅包含依赖项管理功能,而没有插件声明或直接引用Spring或Spring Boot的功能。 你可以使用Spring Boot父POM,或者使用Spring Boot的BOM( spring-boot-dependencies )来管理Spring Boot版本。
请在你的项目中添加BOM:
xml
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-bom</artifactId>
<version>1.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>为特定组件添加依赖项
文档中的每个后续部分展示了需要添加到项目的构建系统中的依赖项。